//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include <Registry.hpp>
#include <OleCtrls.hpp>
#include "SYNCOMLib_OCX.h"
#include <AppEvnts.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm, public _ISynDeviceEvents
{
__published:	// IDE-verwaltete Komponenten
	TButton *ok;
	TButton *cancel;
	TTrayIcon *TrayIcon1;
	TPopupMenu *PopupMenu1;
	TMenuItem *Settings1;
	TMenuItem *About1;
	TMenuItem *Exit1;
	TPageControl *pages;
	TTabSheet *scrollTab;
	TTabSheet *tapTab;
	TMenuItem *globalActive;
	TMenuItem *N1;
	TButton *defaults;
	TTabSheet *generalTab;
	TTimer *reactivateTimer;
	TGroupBox *ScrollTypeGroupBox;
	TCheckBox *scrollLinearEdge;
	TGroupBox *ScrollSettingsGroupBox;
	TTrackBar *scrollAcc;
	TGroupBox *ScrollModeGroupBox;
	TRadioButton *scrollCompatible;
	TRadioButton *scrollSmooth;
	TLabel *Label1;
	TGroupBox *SystemGroupBox;
	TCheckBox *startWithWindows;
	TGroupBox *GroupBox5;
	TRadioButton *scrollSmart;
	TLabel *tapMaxDistanceLabel;
	TTrackBar *tapMaxDistance;
	TCheckBox *scrollAccEnabled;
	TComboBox *tapOneOne;
	TLabel *Label2;
	TLabel *Label3;
	TComboBox *tapThree;
	TTrackBar *scrollSpeed;
	TLabel *scrollSpeedLabel;
	TComboBox *tapTwo;
	TLabel *Label4;
	TLabel *Label5;
	TComboBox *tapTwoOne;
	TGroupBox *EnableScrollingGroupBox;
	TCheckBox *EnableTwoFingerScrollCheckBox;
	TCheckBox *EnableThreeFingerScrollCheckBox;
	TCheckBox *scrollHorizontalCheckBox;
	TGroupBox *EnvyGroupBox;
	TCheckBox *deadzoneCheckBox;
	TCheckBox *preventMouseSkipCheckBox;
	TBalloonHint *BalloonHint1;
	void __fastcall Settings1Click(TObject *Sender);
	void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
	void __fastcall Exit1Click(TObject *Sender);
	void __fastcall okClick(TObject *Sender);
	void __fastcall cancelClick(TObject *Sender);
	void __fastcall About1Click(TObject *Sender);
	void __fastcall defaultsClick(TObject *Sender);
	void __fastcall reactivateTimerTimer(TObject *Sender);
	void __fastcall Label1Click(TObject *Sender);
	void __fastcall scrollAccEnabledClick(TObject *Sender);
	void __fastcall EnableTwoFingerScrollCheckBoxClick(TObject *Sender);
	void __fastcall ToggleScrollSettingsEnabled(bool e);
	void __fastcall EnableThreeFingerScrollCheckBoxClick(TObject *Sender);
	void __fastcall RefreshScrollSettings();

protected:
    void __fastcall Dispatch(void *Message);
private:	// Benutzer Deklarationen
	TRegistry *settings;
	HRESULT STDMETHODCALLTYPE OnSynDevicePacket(long);
	TSynAPI *synAPI;
	TSynDevice *synTouchPad;
	ISynPacket *synPacket;

	bool fIsPadAcquired;
	bool fSynTapState;
	bool fIsDeviceTapLocked;
	// attributes for tracking number of fingers on trackpad
	long fInitialNumberOfFingers;
	long fLastNumberOfFingers;
	long fLastNumberOfFingersTimestamp;
	long fNoFingersTimestamp;

	// tap attributes
	long fTapLastNumberOfFingers;
	long fTapStartTime;
	long fTapTouchTime;
	long fScrollTouchTimestamp;
	long fTapDistance;
	POINT fTapTouchPos;
	// scroll attributes
	POINT fScrollTouchPos;
	long fScrollBuffer;
	long fScrollLastXDelta;
	long fScrollLastYDelta;
	bool fScrollNotEdge;
	int fScrollMode;
	// end attributes
	// helpers
	bool __fastcall handleTapPacket(long, long, long, long);
	bool __fastcall handleScrollPacket(long, long, long, long);
	bool __fastcall handleTwoFingerScroll(long, long, long, long);

	void __fastcall SettingsLoad(bool=false);
	void __fastcall SettingsSave();
	void __fastcall AcquirePad(bool, bool=false);
	void __fastcall LockDeviceTap(bool);
	bool __fastcall DoTap(int);
	bool __fastcall DoScroll(long, long);
	void __fastcall DoHorizontalScroll(long);
	void __fastcall DoVerticalScroll(long);
	// end helpers

public:		// Benutzer Deklarationen
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
